var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("BaseModuleUI"),
    a = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("PureHelper"),
    s = e("sdkConfig"),
    l = e("AD"),
    c = cc._decorator,
    d = c.ccclass,
    h = c.property,
    _ = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.touch_node = null),
                (t.touch_bg = null),
                (t.touch_bar = null),
                (t.use_skill_list = []),
                (t.attack_node = null),
                (t.skill_one_node = null),
                (t.skill_two_node = null),
                (t.native_icon_node = []),
                t
            );
        }
        return (
            __extends(t, e),
            (t.prototype.initView = function () {
                for (var e = 0; e < this.native_icon_node.length; e++)
                    this.native_icon_node[e].active =
                        s.default.platform != s.EPlatform.No_AD &&
                        !l.default.getInstance().getGameTestVersion() &&
                        !i.GlobalParams.PlayGuideMode;
                this.attack_node.addComponent(cc.Button),
                    this.skill_one_node.addComponent(cc.Button),
                    this.skill_two_node.addComponent(cc.Button),
                    (this.attack_node.getComponent(cc.Button).transition = cc.Button.Transition.SCALE),
                    (this.attack_node.getComponent(cc.Button).zoomScale = 0.9),
                    (this.skill_one_node.getComponent(cc.Button).transition = cc.Button.Transition.SCALE),
                    (this.skill_one_node.getComponent(cc.Button).zoomScale = 0.9),
                    (this.skill_two_node.getComponent(cc.Button).transition = cc.Button.Transition.SCALE),
                    (this.skill_two_node.getComponent(cc.Button).zoomScale = 0.9);
            }),
            (t.prototype.addEvent = function () {
                this.touch_node.on(cc.Node.EventType.TOUCH_START, this.TouchStart, this),
                    this.touch_node.on(cc.Node.EventType.TOUCH_MOVE, this.TouchMove, this),
                    this.touch_node.on(cc.Node.EventType.TOUCH_END, this.TouchEnd, this),
                    this.touch_node.on(cc.Node.EventType.TOUCH_CANCEL, this.TouchEnd, this),
                    this.attack_node.on("click", this.playerAttack, this),
                    this.skill_one_node.on("click", this.playerSkillOne, this),
                    this.skill_two_node.on("click", this.playerSkillTwo, this),
                    cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
            }),
            (t.prototype.playerAttack = function () {
                i.GlobalParams.GameStart && this.emitEvent(a.default.SEND_PLAYER_FREE_SKILL);
            }),
            (t.prototype.playerSkillOne = function () {
                i.GlobalParams.GameStart &&
                    (this.emitEvent(a.default.SEND_PLAYER_FREE_SKILL_ONE),
                    this.skill_one_node.getChildByName("cooling").active ||
                        ((this.use_skill_list[0].node.active = !0),
                        this.use_skill_list[0].setAnimation(0, "animation", !0)));
            }),
            (t.prototype.playerSkillTwo = function () {
                i.GlobalParams.GameStart &&
                    (this.emitEvent(a.default.SEND_PLAYER_FREE_SKILL_TWO),
                    this.skill_two_node.getChildByName("cooling").active ||
                        ((this.use_skill_list[1].node.active = !0),
                        this.use_skill_list[1].setAnimation(0, "animation", !0)));
            }),
            (t.prototype.onKeyUp = function (e) {
                switch (e.keyCode) {
                    case cc.macro.KEY.a:
                        this.emitEvent(a.default.SEND_PLAYER_FREE_SKILL);
                        break;
                    case cc.macro.KEY.s:
                        this.emitEvent(a.default.SEND_PLAYER_FREE_SKILL_ONE);
                        break;
                    case cc.macro.KEY.d:
                        this.emitEvent(a.default.SEND_PLAYER_FREE_SKILL_TWO);
                }
            }),
            (t.prototype.TouchStart = function (e) {
                var t = e.touch.getLocation();
                (t = this.touch_node.convertToNodeSpaceAR(t)), this.touch_bg.setPosition(t);
            }),
            (t.prototype.TouchMove = function (e) {
                var t = e.touch.getLocation();
                (t = this.touch_bg.convertToNodeSpaceAR(t)),
                    Math.abs(r.default.Distance(t, cc.v2(0, 0))) > 100 &&
                        (t = r.default.getTailPosOuter(t, cc.v2(0, 0), -100)),
                    this.touch_bar.setPosition(t);
                var o = cc.v2(t.x, t.y).sub(cc.v2(0, 0)).normalize();
                this.emitEvent(a.default.SEND_PLAYER_MOVE_INFO, o);
            }),
            (t.prototype.TouchEnd = function () {
                this.touch_bar.setPosition(cc.v2(0, 0)),
                    this.emitEvent(a.default.SEND_PLAYER_STOP_MOVE_INFO),
                    this.touch_bg.setPosition(cc.v2(-80, -20));
            }),
            __decorate([h(cc.Node)], t.prototype, "touch_node", void 0),
            __decorate([h(cc.Node)], t.prototype, "touch_bg", void 0),
            __decorate([h(cc.Node)], t.prototype, "touch_bar", void 0),
            __decorate([h(sp.Skeleton)], t.prototype, "use_skill_list", void 0),
            __decorate([h(cc.Node)], t.prototype, "attack_node", void 0),
            __decorate([h(cc.Node)], t.prototype, "skill_one_node", void 0),
            __decorate([h(cc.Node)], t.prototype, "skill_two_node", void 0),
            __decorate([h(cc.Node)], t.prototype, "native_icon_node", void 0),
            __decorate([d], t)
        );
    })(n.default);
o.default = _;
